﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using DAL.Entity;
using DAL.Persistencia;

namespace NewTierra.Pages
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void AutenticarUsuario(object sender, AuthenticateEventArgs e)
        {
            try
            {
                string Email = formLogin.UserName;

                string Senha = FormsAuthentication.HashPasswordForStoringInConfigFile
                                                        (formLogin.Password, "MD5");

                UsuarioDAL d = new UsuarioDAL();

                Usuario u = d.ObterUsuario(Email, Senha);

                if (u != null)
                {
                    Application.Add("usuario", u);

                    e.Authenticated = true;
                }
                else
                {
                    e.Authenticated = false;
                }
            }
            catch (Exception ex)
            {
                formLogin.FailureText = ex.Message;
            }

        }
    }
}